<?php

/**
 * 类的说明信息
 */
class Product {

}

$p1 = new Product();
$p2 = new Product();

var_dump($p1, $p2);

class ShopProduct {
    public $title        = '商品名称';
    public $producerName = '制造商名称';
    public $place        = '产地';
    public $price        = 0;
    private $discount    = 0;
    protected $sell      = 1;

    function __construct($title, $producerName, $place, $price) {
        $this->title        = $title;
        $this->producerName = $producerName;
        $this->place        = $place;
        $this->price        = $price;
    }

    public function getTitle($value = '') {
        return $this->title;
    }

    public function getSell($value = '') {
        return $this->sell;
    }
}

// $producer1 = new ShopProduct();
// // echo $producer1->title;
// // echo '<br />';

// // //改变对象的属性
// // $producer1->title = '书籍';
// // echo $producer1->title;

// echo $producer1->getTitle();
// echo $producer1->getSell();

$p2        = new ShopProduct('背单词3000', '北京人民出版社', '北京', 134);
$producer3 = new ShopProduct('《信息简史》', '人民邮电出版社', '北京', 69);

// echo $p2->title;
echo $producer3->title;

//以下内容会报错，private和protected属性不能在对象中访问
// echo $producer1->discount;
// echo $producer1->sell;
//
class StaticExample {
    static public $siteName = '';
    public $siteUrl         = 'www.xbmu.edu.cn';
    static public function sayHello() {
        echo 'hello';
        // 静态方法不能访问这个类中的普通属性
        // echo $this->siteurl;
    }
    static public function setSiteName($str = '西北民族大学') {
        // 在类内部，可以使用self关键字访问当前类
        self::$siteName = $str;
        echo self::$siteName;
    }
}

// 静态属性及方法的访问
echo StaticExample::$siteName;
StaticExample::sayHello();
StaticExample::setSiteName();
echo StaticExample::$siteName;

$se = new StaticExample();

// 不能在对象中调用静态方法和属性
echo $se->siteName;
var_dump($se);
$se->sayHello();
?>
